#!/usr/bin/lua
require("apm_core")

-- 注意apm_global.lua里定义的变量/函数,不要重复定义

-- http hook函数
-- return 1: 该数据不上报;其它:上报数据
function post_analysis()
	local i_ret_fun;
	local s_key;
	local ApmData = require("ApmData");
	
	logDebug("lua_hook_post start...");
	
	logDebug("l4:%d l7:%d ", ApmData.getL7Proto() , ApmData.getL7Proto());
	
	s_key = "request.a01";
	
	logDebug("addField=%d", ApmData.addField(s_key, "b02"));
	logDebug("addField=%d", ApmData.addField(s_key, 113));
	logDebug("addField=%d", ApmData.addField(s_key, 113.123));
	-- ApmData.addField(s_key, 11);

	ApmData.addField("request.a03", 22.22);

	i_ret_fun = ApmData.getFieldSize(s_key);
	logDebug("count(%s) %d", s_key , i_ret_fun);
	
	i_ret_fun = ApmData.exists("request.a02");
	logDebug("exist(request.a02):%s", tostring(i_ret_fun));
	
	-- i_ret_fun = ApmData.getField(s_key, 3);
	i_ret_fun = ApmData.getField(s_key, 1);
	if i_ret_fun ~= nil then
		logDebug("ApmData.getField(%s, 1) ret=%s", s_key ,i_ret_fun);
	else
		logDebug("ApmData.getField(%s, 1) ret=nil", s_key);
	end
	ApmData.delFields(s_key);
	
	--replaceField(s_key, "replace02");
	--logDebug("%s", ApmData.dumpFields(true));
	logDebug(">l4:" .. ApmData.getL7Proto() .. " " .. ApmData.getSrcIp() .. ":".. ApmData.getSrcPort() .. "->" .. ApmData.getDstIp() .. ":" .. ApmData.getDstPort() );
	logDebug(">l4:" .. ApmData.getL7Proto() .. " " .. ApmData.getSrcIp() .. ":".. ApmData.getSrcPort() .. "->" .. ApmData.getDstIp() .. ":" .. ApmData.getDstPort() );
	
	logDebug("lua_hook_post end...");
	
	return 0;
end
